*Replication codes for A Comparative Study of Arab Migrants in Democracies and Autocracies

*Last update: 03/01/23

**Recoding values using survey as reference 
recode years_residing (1=5) (2=4) (3=3) (4=2) (5=1), gen(yrs_residing_recode)

recode visitcoo_freq (1=4) (2=3) (3=2) (4=1), gen(visitcoo_freqrc)

recode familyincoo (1=0) (2=1), gen(familyincoo_bin)

recode speakfamcoo_freq (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1), gen(speakfamcoo_freqrc)
recode speakfriendscoo_freq (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1), gen(speakfriendscoo_freqrc)

recode suggest_support_coopol (21=0) (22=1), gen(suggest_support_coopol_bin) 
recode suggest_support_cooparty (21=0) (22=1), gen(suggest_support_cooparty_bin) 
recode suggest_support_coopolicy (21=0) (22=1), gen(suggest_support_coopolicy_bin) 

recode remit_freq (1=4) (2=3) (3=2) (4=1), gen(remit_freqrc)
gen remit_binary=0 if remit_freqrc==1
replace remit_binary=1 if remit_freqrc==2 | remit_freqrc==3 | remit_freqrc==4
recode receipt_freq (1=4) (2=3) (3=2) (4=1), gen(receipt_freqrc)
gen receipt_binary=0 if receipt_freqrc==1
replace receipt_binary=1 if receipt_freqrc==2 | receipt_freqrc==3 | receipt_freqrc==4

recode vote_cooelection (1=0) (2=1), gen(vote_cooelection_bin)
gen coo_external_vote=.

recode campaign_coo_pol (1=0) (2=1), gen campaign_coo_polrc_bin)

drop if age==1

recode sex (1=1) (2=0) (3=.), gen(male)

gen married=1 if social_status==1
replace married=0 if social_status!=1 & social_status!=.
gen citizen=1 if citizenship_status==1 | citizenship_status==2
replace citizen=0 if citizenship_status!=1 & citizenship_status!=2 & citizenship_status!=.
gen refugee=1 if citizenship_status==5
replace refugee=0 if citizenship_status!=5 & citizenship_status!=.

gen will_return=0 if return_intention==1
replace will_return=1 if return_intention!=1 & return_intention!=.
replace will_return=. if return_intention==5
*this is maybe/unsure

recode return_intention (5=.) (2=1) (3=2) (4=3) (1=4), gen(return_intent_recode)

gen college_grad=1 if education>3
replace college_grad=0 if education<5 & education!=.

gen employed=1 if employment_status==1 | employment_status==2
replace employed=0 if employment_status!=1 & employment_status!=2 and employment_status!=.

gen muslim=1 if religion==1
replace muslim=0 if religion!=1 & religion!=.

recode income_situation (1=4) (2=3) (3=2) (2=1), gen(income_situationrc)

gen cootopic_pol=1 if coo_topic1==1 | coo_topic2==1 | coo_topic3==1 | coo_topic4==1 | coo_topic5==1
replace cootopic_pol=0 if coo_topic1!=1 & coo_topic2!=1 & coo_topic3!=1 & coo_topic4!=1 & coo_topic5!=1 & topics_about_coo!=""

gen cootopic_soc=1 if coo_topic1==2 | coo_topic2==2 | coo_topic3==2 | coo_topic4==2 | coo_topic5==2
replace cootopic_soc=0 if coo_topic1!=2 & coo_topic2!=2 & coo_topic3!=2 & coo_topic4!=2 & coo_topic5!=2 & topics_about_coo!=""

gen cootopic_econ=1 if coo_topic1==3 | coo_topic2==3 | coo_topic3==3 | coo_topic4==3 | coo_topic5==3
replace cootopic_econ=0 if coo_topic1!=3 & coo_topic2!=3 & coo_topic3!=3 & coo_topic4!=3 & coo_topic5!=3 & topics_about_coo!=""

gen cootopic_personal=1 if coo_topic1==4 | coo_topic2==4 | coo_topic3==4 | coo_topic4==4 | coo_topic5==4
replace cootopic_personal=0 if coo_topic1!=4 & coo_topic2!=4 & coo_topic3!=4 & coo_topic4!=4 & coo_topic5!=4 & topics_about_coo!=""

gen cootopic_gen=1 if coo_topic1==5 | coo_topic2==5 | coo_topic3==5 | coo_topic4==5 | coo_topic5==5
replace cootopic_gen=0 if coo_topic1!=5 & coo_topic2!=5 & coo_topic3!=5 & coo_topic4!=5 & coo_topic5!=5 & topics_about_coo!=""


gen impcoo_econ=1 if imp_coo1==1 | imp_coo2==1| imp_coo3==1
replace impcoo_econ=0 if imp_coo1!=1 & imp_coo2!=1 & imp_coo3!=1 & three_most_imp_coo!=""

gen impcoo_corrupt=1 if imp_coo1==2 | imp_coo2==2| imp_coo3==2
replace impcoo_corrupt=0 if imp_coo1!=2 & imp_coo2!=2 & imp_coo3!=2 & three_most_imp_coo!=""

gen impcoo_dem=1 if imp_coo1==3 | imp_coo2==3| imp_coo3==3
replace impcoo_dem=0 if imp_coo1!=3 & imp_coo2!=3 & imp_coo3!=3 & three_most_imp_coo!=""

gen impcoo_rights=1 if imp_coo1==7 | imp_coo2==7| imp_coo3==7
replace impcoo_rights=0 if imp_coo1!=7 & imp_coo2!=7 & imp_coo3!=7 & three_most_imp_coo!=""

gen impcoo_stability=1 if imp_coo1==4 | imp_coo2==4| imp_coo3==4
replace impcoo_stability=0 if imp_coo1!=4 & imp_coo2!=4 & imp_coo3!=4 & three_most_imp_coo!=""

gen impcoo_foreign=1 if imp_coo1==5 | imp_coo2==5| imp_coo3==5
replace impcoo_foreign=0 if imp_coo1!=5 & imp_coo2!=5 & imp_coo3!=5 & three_most_imp_coo!=""

gen impcoo_services=1 if imp_coo1==6 | imp_coo2==6| imp_coo3==6
replace impcoo_services=0 if imp_coo1!=6 & imp_coo2!=6 & imp_coo3!=6 & three_most_imp_coo!=""

gen impcoo_environ=1 if imp_coo1==8 | imp_coo2==8| imp_coo3==8
replace impcoo_environ=0 if imp_coo1!=8 & imp_coo2!=8 & imp_coo3!=8 & three_most_imp_coo!=""


*Checking null model w/ COO as Level 2
meologit support_coodem || coo_ccode: 

meologit support_coodem || cor_ccode:
**no support for using a multilevel model 

*Factor analyses
factor visitcoo_freqrc remit_freqrc receipt_freqrc speakfamcoo_freqrc positive_coo close_coo, pcf

factor visitcoo_freqrc remit_freqrc receipt_freqrc positive_coo close_coo, pcf

factor informed_coopol concerned_coo_pol informed_coo_econsoc positive_coo, pcf 

factor informed_coopol concerned_coo_pol informed_coo_econsoc contribute_cooecon advocate_coopol, pcf 

**creating indices 
*closeness to COO
replace visitcoo_freqrc=0 if visitcoo_freqrc==.
replace positive_coo=0 if positive_coo==.
replace close_coo=0 if close_coo==.
**so stata will still add all the variables when there's a missing value

gen coo_closeness_index=visitcoo_freqrc+positive_coo+close_coo

gen coo_closeness_index2=positive_coo+close_coo

replace visitcoo_freqrc=. if visitcoo_freqrc==0
replace positive_coo=. if positive_coo==0
replace close_coo=. if close_coo==0
**to reinstate missing values

***generates index 0-14
replace coo_closeness_index=. if visitcoo_freqrc==. & positive_coo==. & close_coo==.
**to reinstate missing values across all variables

*interest in COO politics
replace informed_coo_econsoc=0 if informed_coo_econsoc==.
replace informed_coopol=0 if informed_coopol==.

gen coo_informed_index=(informed_coo_econsoc+informed_coopol)/2

replace informed_coo_econsoc=. if informed_coo_econsoc==0
replace informed_coopol=. if informed_coopol==0

replace coo_informed_index=. if informed_coo_econsoc==. & informed_coopol==.

*Testing models 
meologit support_coodem dem_cor || ccode:
ologit support_coodem dem_cor i.ccode
ologit support_coodem dem_cor i.cor_ccode

*Testing H1ab
gen coo_connection_index=.
replace remit_freqrc=0 if remit_freqrc==.
replace receipt_freqrc=0 if receipt_freqrc==.

replace coo_connection_index=remit_freqrc+receipt_freqrc

replace remit_freqrc=. if remit_freqrc==0
replace receipt_freqrc=. if receipt_freqrc==0

replace coo_connection_index=. if remit_freqrc==. & receipt_freqrc==. 
gen coo_connection_index2=coo_connection_index/4

ologit support_coodem dem_cor remit_freqrc close_coo informed_coopol age male income_situationrc education married yrs_residing_recode

svy: ologit support_coodem dem_cor remit_freqrc close_coo informed_coopol age male income_situationrc education married yrs_residing_recode

svy: ologit support_coodem dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode

svy: ologit support_coodem dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode coo_external_vote gdppc_5yravg

svy: ologit support_coodem dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode coo_external_vote gdppc_5yravg i.coo_ccode

margins, dydx(dem_cor)
marginsplot, title("Effect of migrant living in a democratic COR" "on likelihood of supporting democracy in COO", size(medium) color(black)) graphregion(color(white)) xtitle("A/D: People like me should support democracy in their country of origin") ciopt(lpattern(dash)) yline(0)

*Testing H2ab
svy: ologit censorship_for_morals dem_cor remit_freqrc close_coo informed_coopol age male income_situationrc education married yrs_residing_recode

svy: ologit censorship_for_morals dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode

svy: ologit censorship_for_morals dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode coo_external_vote gdppc_5yravg 

svy: ologit censorship_for_morals dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode coo_external_vote gdppc_5yravg i.coo_ccode

marginsplot, title("Effect of migrant living in a democratic COR" "on likelihood of supporting censorship", size(medium) color(black)) graphregion(color(white)) xtitle("A/D: Censorship of films, television, and magazines is necessary to uphold moral standards") ciopt(lpattern(dash)) yline(0)

*Testing H3ab
svy: logit impcoo_dem dem_cor remit_freqrc close_coo informed_coopol age male income_situationrc education married yrs_residing_recode

svy: logit impcoo_dem dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode

svy: logit impcoo_dem dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode coo_external_vote gdppc_5yravg

svy: logit impcoo_dem dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode coo_external_vote gdppc_5yravg i.coo_ccode

margins, dydx(dem_cor)
marginsplot

*Testing H4ab
svy: ologit unconditional_coosupport dem_cor remit_freqrc close_coo informed_coopol age male income_situationrc education married yrs_residing_recode

svy: ologit unconditional_coosupport dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode

svy: ologit unconditional_coosupport dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode coo_external_vote gdppc_5yravg 

svy: ologit unconditional_coosupport dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode coo_external_vote gdppc_5yravg i.coo_ccode

margins, dydx(dem_cor)

*Testing H5ab
svy: logit cootopic_pol dem_cor remit_freqrc close_coo informed_coopol age male income_situationrc education married yrs_residing_recode

svy: logit cootopic_pol dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode

svy: logit cootopic_pol dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode coo_external_vote gdppc_5yravg

svy: logit cootopic_pol dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode coo_external_vote gdppc_5yravg i.coo_ccode

margins, dydx(dem_cor)
marginsplot, recast(scatter) title("Probability of migrant discussing politics" "based on regime type of COR" , size(medium) color(black)) ciopt(lpattern(dash)) graphregion(color(white))

*Testing H6ab
svy: logit suggest_support_coopolicy_bin dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode coo_external_vote gdppc_5yravg i.coo_ccode

svy: ologit donate_social_coo dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode coo_external_vote gdppc_5yravg i.coo_ccode

svy: logit vote_cooelection_bin dem_cor remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married yrs_residing_recode gdppc_5yravg i.coo_ccode if coo_external_vote==1

margins dem_cor
marginsplot 

*Appendix
svy: logit vote_cooelection_bin i.dem_cor i.yrs_residing_recode remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married  gdppc_5yravg i.coo_ccode if coo_external_vote==1

svy: logit vote_cooelection_bin i.dem_cor##i.yrs_residing_recode remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married  gdppc_5yravg i.coo_ccode if coo_external_vote==1

margins, dydx(i.yrs_residing_recode) over(i.dem_cor)

svy: logit vote_cooelection_bin i.dem_cor i.will_return remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married  gdppc_5yravg i.coo_ccode if coo_external_vote==1

svy: logit vote_cooelection_bin i.dem_cor##i.will_return remit_freqrc coo_closeness_index2 coo_informed_index age male income_situationrc education married  gdppc_5yravg i.coo_ccode if coo_external_vote==1

margins, dydx(i.will_return) over(i.dem_cor)
